package socket.udp.unicast;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author 周宇
 * @create 2020-05-25 18:08
 */
public class ReceiveServer {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10000);
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            ds.receive(dp);
            byte[] data = dp.getData();//发送的数据
            int length = dp.getLength();//发送了多少个字节
            System.out.println(new String(data, 0, length));
        }
        // ds.close();
    }
}
